<?php
function insertItemStock($itemId,$quantity,$plusMinus)
{
  $stockQry = "SELECT itemStockId
	               FROM itemstock
	              WHERE itemId = ".$itemId;
  $stockQryRes = mysql_query($stockQry);
  if($stockRow = mysql_fetch_array($stockQryRes))
  {
    $updateStockQry = "UPDATE itemstock
                          SET quantity = quantity ".$plusMinus." ".$quantity."
                        WHERE itemStockId = ".$stockRow['itemStockId'];
    $updateStockQryRes = mysql_query($updateStockQry);
  }
  else
  {	
	  $insNewStock = "INSERT INTO itemstock (itemId,quantity)
	                   VALUE (".$itemId.",".$quantity.")";
	  $insNewStockRes = mysql_query($insNewStock);
	  if(!$insNewStockRes)
	  {
	    die("Insert Query Error : ". mysql_error());
	  }
	}
}
?>